<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Creates a new object with modified timestamp</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="datetimeimmutable.getlasterrors.html">« DateTimeImmutable::getLastErrors</a></li>
      <li style="float: right;"><a href="datetimeimmutable.set-state.html">DateTimeImmutable::__set_state »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.datetimeimmutable.html">DateTimeImmutable</a></li>
    <li>Creates a new object with modified timestamp</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="datetimeimmutable.modify" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">DateTimeImmutable::modify</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.5.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">DateTimeImmutable::modify</span> &mdash; <span class="dc-title">Creates a new object with modified timestamp</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-datetimeimmutable.modify-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>DateTimeImmutable::modify</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$modifier</code></span>): <span class="type"><span class="type"><a href="class.datetimeimmutable.html" class="type DateTimeImmutable">DateTimeImmutable</a></span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   Creates a new <span class="type"><a href="class.datetimeimmutable.html" class="type DateTimeImmutable">DateTimeImmutable</a></span> object with modified timestamp.
   The original object is not modified.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-datetimeimmutable.modify-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>
<code class="parameter">modifier</code></dt>

    <dd>

     <p class="para">日期/时间字符串。正确格式的说明详见 <a href="datetime.formats.html" class="link">日期与时间格式</a>。</p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-datetimeimmutable.modify-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns a new modified DateTimeImmutable object 或者在失败时返回 <strong><code>false</code></strong>.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-datetimeimmutable.modify-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-2018">
   <p><strong>示例 #1 <span class="function"><strong>DateTimeImmutable::modify()</strong></span> example</strong></p>
   <div class="example-contents"><p>面向对象风格</p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$date&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DateTimeImmutable</span><span style="color: #007700">(</span><span style="color: #DD0000">'2006-12-12'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$newDate&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$date</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">modify</span><span style="color: #007700">(</span><span style="color: #DD0000">'+1&nbsp;day'</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$newDate</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #DD0000">'Y-m-d'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程会输出：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
2006-12-13
</pre></div>
   </div>
  </div>
  <div class="example" id="example-2019">
   <p><strong>示例 #2 Beware when adding or subtracting months</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$date&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DateTimeImmutable</span><span style="color: #007700">(</span><span style="color: #DD0000">'2000-12-31'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$newDate1&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$date</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">modify</span><span style="color: #007700">(</span><span style="color: #DD0000">'+1&nbsp;month'</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$newDate1</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #DD0000">'Y-m-d'</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$newDate2&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$newDate1</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">modify</span><span style="color: #007700">(</span><span style="color: #DD0000">'+1&nbsp;month'</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$newDate2</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #DD0000">'Y-m-d'</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程会输出：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
2001-01-31
2001-03-03
</pre></div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-datetimeimmutable.modify-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"><span class="function"><a href="datetimeimmutable.add.html" class="function" rel="rdfs-seeAlso">DateTimeImmutable::add()</a> - Returns a new object, with added amount of days, months, years, hours, minutes and seconds</span></li>
   <li class="member"><span class="function"><a href="datetimeimmutable.sub.html" class="function" rel="rdfs-seeAlso">DateTimeImmutable::sub()</a> - Subtracts an amount of days, months, years, hours, minutes and seconds</span></li>
   <li class="member"><span class="function"><a href="datetimeimmutable.setdate.html" class="function" rel="rdfs-seeAlso">DateTimeImmutable::setDate()</a> - Sets the date</span></li>
   <li class="member"><span class="function"><a href="datetimeimmutable.setisodate.html" class="function" rel="rdfs-seeAlso">DateTimeImmutable::setISODate()</a> - Sets the ISO date</span></li>
   <li class="member"><span class="function"><a href="datetimeimmutable.settime.html" class="function" rel="rdfs-seeAlso">DateTimeImmutable::setTime()</a> - Sets the time</span></li>
   <li class="member"><span class="function"><a href="datetimeimmutable.settimestamp.html" class="function" rel="rdfs-seeAlso">DateTimeImmutable::setTimestamp()</a> - Sets the date and time based on a Unix timestamp</span></li>
  </ul>
 </div>


</div></div></div></body></html>